<?php
/**
 * @author Eugenio Fage
 * inspired by meneame
 */
class BanBehavior extends ModelBehavior {
	var $banComponent;
		
	function setup(&$model, $config = array()){	}
	
	function beforeValidate(&$model){
		if(!$this->banComponent){
			App::import('Component', 'Ban');    
        	$this->banComponent = new BanComponent(); 
		}
				
	}
		
	/**
	 * 
	 * Check if a mail is banned
	 * @param $check a array with the mail
	 * @param $checkType false if check the full mail, if domain check domain is ban, if mailbox use the mailbox name 
	 * 
	 */
	function notBannedEmail($check,$checkType=null){
		if(!$email=array_pop($check)) return true;
		return $this->banComponent->notBannedEmail($email,$checkType);
	}
				
	function notBannedHostname($check,$deep=false,$first_level=false){
		if(!$hostname=array_pop($check)) return true;
				
		return $this->banComponent->notBannedHostname($hostname,$first_level);
	}
		
	/**
	 * 
	 * check is the text contain a forbidden word
	 * @param $check array with the text
	 */
	function notBannedWord($check){
		if(!$text=array_pop($check)) return true;
		return $this->banComponent->notBannedWord($text);
	}	
}